﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class MainLineManager : MonoBehaviour
{
    Text moneyValue;//元宝数

    public Transform diyizhang;//第一章
    public Transform dierzhang;//第二章
    public GameObject xiangshanghua;//向上滑
    public GameObject xiangxiahua;//向下滑
    float lastTime;
    public GameObject tishi;//提示未开启
    public GameObject yindao16;
    public Image[] guanqia;
    string[] guanqiaImagePath = { "MainLine/222", "MainLine/333", "MainLine/444", "MainLine/555", "MainLine/666", "MainLine/777", "MainLine/888", "MainLine/999", "MainLine/101010", "MainLine/111111", "MainLine/121212" };
    public Image[] xian;
    string[] xianImagePath = { "MainLine/line1", "MainLine/line2", "MainLine/line3", "MainLine/line4", "MainLine/line5", "MainLine/line5", "MainLine/line1", "MainLine/line2", "MainLine/line3", "MainLine/line4", "MainLine/line5" } ;
    void Start()
    {
        ShowLevel();
        moneyValue = GameObject.Find("moneyValue").GetComponent<Text>();
        moneyValue.text = VariableDocument.GetInstance.money.ToString();
        yindao16.transform.GetChild(2).gameObject.SetActive(false);
        yindao16.transform.GetChild(1).gameObject.SetActive(false);
        if (VariableDocument.GetInstance.yindaoid == 15)
        {
            yindao16.transform.GetChild(2).gameObject.SetActive(true);
            yindao16.transform.GetChild(1).gameObject.SetActive(true);
        }

    }


    void Update()
    {
        if (lastTime > 0)
        {
            lastTime -= 1 * Time.deltaTime;
        }

    }

    public void ClickMainLineSlidingBtn()
    {
        if (lastTime <= 0 && VariableDocument.GetInstance.chapters == 1)
        {
            lastTime = 0.5f;
            VariableDocument.GetInstance.chapters = 2;
            diyizhang.DOLocalMoveY(1334, 0.1f * 1334f * Time.deltaTime);
            dierzhang.DOLocalMoveY(0, 0.1f * 1334 * Time.deltaTime);
            xiangxiahua.SetActive(true);
            xiangshanghua.SetActive(false);
        }
        if (lastTime <= 0 && VariableDocument.GetInstance.chapters == 2)
        {
            lastTime = 0.5f;
            VariableDocument.GetInstance.chapters = 1;
            diyizhang.DOLocalMoveY(0, 0.1f * 1334f * Time.deltaTime);
            dierzhang.DOLocalMoveY(-1334, 0.1f * 1334 * Time.deltaTime);
            xiangshanghua.SetActive(true);
            xiangxiahua.SetActive(false);
        }
    }

    //关卡开启的设置
    public void ShowLevel()
    {
        for(int fb = 0; fb < VariableDocument.GetInstance.max_checkpoint; fb++)
        {
            guanqia[fb].sprite = Resources.Load<Sprite>(guanqiaImagePath[fb]);
            xian[fb].sprite = Resources.Load<Sprite>(xianImagePath[fb]);
        }

    }
    //进入关卡
    public void ClickGuanqia(int zx)
    {
        if(zx <= VariableDocument.GetInstance.max_checkpoint)
        {
            if (VariableDocument.GetInstance.yindaoid == 15)
            {
                yindao16.transform.GetChild(2).gameObject.SetActive(false);
                yindao16.transform.GetChild(1).gameObject.SetActive(false);
                VariableDocument.GetInstance.yindaoid = 18;
            }
            GoToInterface.ToInterface("BattleScene");
            VariableDocument.GetInstance.current_checkpoint = zx;
            VariableDocument.GetInstance.timernum = 60 - zx * 3;
            VariableDocument.GetInstance.killtager = 20 + zx * 5;
        }
        else
        {
            tishi.SetActive(true);
            Invoke("tishixiaoshi", 1f);
        }
    }
    void tishixiaoshi()
    {
        tishi.SetActive(false);
    }
}
